package priv.mill.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import priv.mill.model.Book;// log for java

@Controller
@RequestMapping("books")
@SessionAttributes(names= {"booksss"},types= {ArrayList.class})
public class BooksController {
	
	private Logger logger = LoggerFactory.getLogger(BooksController.class);
	
	private static List<Book> books=new ArrayList<>();
	
	{
		books.add(new Book("神雕侠侣",89.7,"渣渣"));
		books.add(new Book("绝代双骄",109.7,"古龙"));
		books.add(new Book("隋唐英雄传",129.7,"黄易"));
	}
	
	@GetMapping("all")
	public String findAll(Map<String, Object> map) {
//		debug
//		info
//		warning
//		error
		logger.error("这就是我写出的日志");
		map.put("books", books);
		return "bs/books";
//		/WEB-INF/jsp/bs/books.jsp
		//spring.mvc.view.suffix=.jsp
//		spring.mvc.view.prefix=/WEB-INF/jsp/
	}
	
	@GetMapping("del")
	public String del(@RequestParam("name") String name,Book book) {
		books.remove(book);
		return "redirect:all";// response.sendRedirect()
	}

}
